﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Tong;
/// <summary>
/// Default 的摘要说明
/// </summary>
public partial class Default_ : Page
{
    string text;

    Int32 i;//设置登录记录次数

    public TongUse TextData = new TongUse();
    Tong.Check.Check Check = new Tong.Check.Check();
    Tong.ThisSiteUse.SiteTong TextThisSite = new Tong.ThisSiteUse.SiteTong();
    protected void Page_Load(object sender, EventArgs e)
    {
        Check.CheckStr();
        ImageButton1.Attributes.Add("style", "cursor:pointer;");
        CopyRight.Text = Tong.TongUse.COPY + TongUse.CopyRight;//加载ＣＯＰＹＲＨＴ
        
    }

    protected void aa(object sender, ImageClickEventArgs e)
    {

        

        if (use.Value.Trim() != "" && pwd.Value != "")//如果输入用户名或密码
        {
            int 记录数=0;
            string pwd1 = TextData.SHA1Sign(pwd.Value.ToString());//加密码
            if (Session["iii"] != null)
            {
                if (int.Parse(Session["iii"].ToString()) < 4)
                {
                    记录数 = TextData.SqlataSet("select * from [use] where uid = '" + use.Value.ToString().Replace("'", "") + "' and pwd = '" + pwd1 + "'").Tables[0].DefaultView.Count;//看看是不是有记录存在
                }
                else
                {
                    记录数 = 0;
                    text = "<script>alert('你已超过最大登录次数');window.close();window.location.href='" + Tong.TongUse.SysPath + "'; </script>";
                }
            }
            else
            {
                记录数 = TextData.SqlataSet("select * from [use] where uid = '" + use.Value.ToString().Replace("'","") + "' and pwd = '" + pwd1 + "'").Tables[0].DefaultView.Count;//看看是不是有记录存在
            }
            if( 记录数 != 1 )
            {
                text = "用户名或密码错误";

                if (Session["iii"] != null)
                {
                    Session["iii"] = Convert.ToInt32(int.Parse(Session["iii"].ToString())+1).ToString();
                    if (int.Parse(Session["iii"].ToString()) >= 4)
                    {
                        text = "<script>alert('你已超过最大登录次数');window.close();window.location.href='"+Tong.TongUse.SysPath+"'; </script>";
                    }
                   
                }
                else
                {
                    Session["iii"] = "1";
                }
            }
            else
            {
                Response.Cookies["admin"].Value = use.Value.Replace("'", "");//便用cookie写入
                TextThisSite.AddNewCX_loginState(use.Value.Replace("'", ""), "LoginX.aspx", "登录系统进行管理操作");
                Response.Redirect("Index.aspx");
            }

        }
        else
        {

            
            
            
            i = i + 1;

            text = "请输入用户名或密码";

        }




        form1_Use.InnerHtml = text;
    }
}
